import verifys from 'service/util/verifys.js'
import reg from 'service/config/reg.js'
export default {
    data() {
        return {
            picCode: '',
            mobile: '',
            smsCode: '',
            password: '',
            // 将此值++，在图形验证码组件中检测该值变化，变化则重新获取验证码
            reauth: 0,
            agreeProto: true
        }
    },
    computed: {
        // 图形验证码在手机号码输入正确的时候显示
        showAuthImg() {
            return reg.mobile.test(this.mobile)
        }
    },
    methods: {
        registerAction() {
            if (!this.agreeProto) {
                $toast.show('请确认您已同意随行贷注册协议')
                return
            }
            if (verifys.verify(['mobile', 'smsCode', 'password'], this) == false) {
                return
            }
            $loading.show()
            var postData = {
                mobile: this.mobile,
                smsCode: this.smsCode,
                password: this.password
            }
            if (this.$route.query.inviteCode) {
                postData.inviteCode = this.$route.query.inviteCode
            }
            $ajax.account.register(postData).then(res => {
                var { code, msg } = res.data
                $toast.show(msg)
                if (code == 'S') {
                    // 上传地理位置信息
                    $wxsdk.postLbs({
                        scene: 1,
                        mobile: this.mobile
                    })
                    // 如果是邀请界面过来的注册，则注册完成后跳转到ways页面，否则是登录页面
                    if (this.$route.query.source == 'share') {
                        $router.replace('/system/ways')
                    } else {
                        $router.replace('/user/login')
                    }
                }
            }).catch(err => {
                $toast.show('网络异常')
            })
        },
        failSms() {
            this.picCode = ''
            this.reauth++
        }
    }
}